import java.util.Arrays;


public class Leetcode1996 {

    public static void main(String[] args) {

    }

    static {
        System.gc();
        System.runFinalization();
    }

    public int numberOfWeakCharacters(int[][] properties) {
        Arrays.sort(properties, (p1, p2) -> p1[0] == p2[0] ? (p1[1] - p2[1]) : (p2[0] - p1[0]));

        int res = 0;
        int defenseMax = 0;
        for (int[] property : properties) {
            if (property[1] >= defenseMax) {
                defenseMax = property[1];
            } else {
                res++;
            }
        }

        return res;
    }
}
